
/****************************************************************************/

int kernelMultitaskerSetProcessBoost(int processId, int boostValue)
{
	int status = 0;
	kernelProcess *changeProcess;

	// Make sure multitasking has been enabled
	if (!multitaskingEnabled)
		return (status = ERR_NOTINITIALIZED);

	if (boostValue < MIN_BOOST_VALUE)
		boostValue = MIN_BOOST_VALUE;
	else if (boostValue > MAX_BOOST_VALUE)
		boostValue = MAX_BOOST_VALUE;

	ACQUIRE_LOCK_PROCESS_QUEUE();

	// We need to find the process structure based on the process Id
	changeProcess = getProcessById(processId);

	if (changeProcess == NULL)
	{
		// The process does not exist
		RELEASE_LOCK_PROCESS_QUEUE();
		return (status = ERR_NOSUCHPROCESS);
	}

	// Permission check.  A privileged process can set the boost of any 
	// other process, but a non-privileged process can only change the 
	// boost of processes owned by the same user.
	if (kernelCurrentProcess->privilege != PRIVILEGE_SUPERVISOR)
	{
		if (kernelCurrentProcess->userId != changeProcess->userId)
		{
			RELEASE_LOCK_PROCESS_QUEUE();
			return (status = ERR_PERMISSION);
		}
	}

	if (boostValue > 0)
	{
		changeProcess->boost = min(min(changeProcess->boost + boostValue, boostValue * 3), MAX_BOOST_VALUE);
	}
	else if (boostValue < 0)
	{
		changeProcess->boost = max(max(changeProcess->boost + boostValue, boostValue * 3), MIN_BOOST_VALUE);
	}

	RELEASE_LOCK_PROCESS_QUEUE();

	return (status = 0);
}

/****************************************************************************/

